package com.fuqi.android.zhongcai.base.view.activity.deprecated;


import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;

import com.android.volley.Response;
import com.android.volley.error.VolleyError;
import com.flyco.animation.ZoomEnter.ZoomInEnter;
import com.flyco.animation.ZoomExit.ZoomOutExit;
import com.flyco.dialog.listener.OnBtnClickL;
import com.flyco.dialog.listener.OnOperItemClickL;
import com.flyco.dialog.widget.ActionSheetDialog;
import com.flyco.dialog.widget.NormalDialog;
import com.fuqi.android.zhongcai.R;
import com.fuqi.android.zhongcai.application.UniApplication;
import com.fuqi.android.zhongcai.base.Constants;
import com.fuqi.android.zhongcai.base.view.activity.BaseActivity;
import com.fuqi.android.zhongcai.base.view.activity.ShowOrderImgAllActivity;
import com.fuqi.android.zhongcai.base.view.activity.UploadImgActivity;
import com.fuqi.android.zhongcai.business.shuig.request.api.OrderDetailApi;
import com.fuqi.android.zhongcai.business.shuig.request.api.OrderHandleApi;
import com.fuqi.android.zhongcai.business.shuig.request.result.OrderDetailResult;
import com.fuqi.android.zhongcai.business.shuig.request.result.OrderHandleResult;
import com.fuqi.android.zhongcai.base.view.widget.EditDialog;
import com.fuqi.android.zhongcai.base.view.widget.TitleBar;
import com.fuqi.android.zhongcai.business.shuig.view.activity.ShuiGCannotInstallActivity;
import com.fuqi.android.zhongcai.business.shuig.view.activity.ShuiGChouChaActivity;
import com.fuqi.android.zhongcai.business.shuig.view.activity.ShuiGCommentActivity;
import com.fuqi.android.zhongcai.business.shuig.view.activity.ShuiGPaiDanActivity;
import com.fuqi.android.zhongcai.business.shuig.view.activity.ShuiGPaiGongActivity;
import com.fuqi.android.zhongcai.utils.ActivityUtils;
import com.fuqi.android.zhongcai.utils.LogUtils;
import com.fuqi.framework.gson.GsonHelper;
import com.fuqi.framework.network.code.HandleCode;
import com.fuqi.framework.network.http.RequestManager;

import butterknife.Bind;
import butterknife.OnClick;
@Deprecated
public class OrderDetailActivity extends BaseActivity {


    @Bind(R.id.bottom_sgdz)
    LinearLayout bottomSgdz;
    @Bind(R.id.btn_submit)
    Button btnSubmit;
    @Bind(R.id.btn_no_contact)
    Button btnNoContact;
    @Bind(R.id.btn_sure_make_order)
    Button btnMakeOrder;

    @OnClick({R.id.btn_submit,R.id.btn_no_contact,R.id.btn_sure_make_order})
    public void onClick(View v){


        if (UniApplication.getInstance().getCurrentRole().equals(Constants.ROLE_GRKH)){
            // 用户
            if (v.getId() == R.id.btn_submit){

                ActivityUtils.startActivity(OrderDetailActivity.this,ShuiGCommentActivity.class);

            }


        } else if (UniApplication.getInstance().getCurrentRole().equals(Constants.ROLE_SGGR)){
            // 施工工人
            if (v.getId() == R.id.btn_submit){

                ActivityUtils.startActivity(OrderDetailActivity.this,UploadImgActivity.class);

            }


        }else if (UniApplication.getInstance().getCurrentRole().equals(Constants.ROLE_JCY)){
            // 监察员
            if (v.getId() == R.id.btn_submit){

                ActivityUtils.startActivity(OrderDetailActivity.this,ShuiGChouChaActivity.class);

            }


        }else if (UniApplication.getInstance().getCurrentRole().equals(Constants.ROLE_NQ)){
            // 内勤

            switch (v.getId()){

                case R.id.btn_no_contact:
                    showBoHuiDialog();
                    break;
                case R.id.btn_sure_make_order:
                    showPaiDanDialog();
                    break;


            }


        }else if (UniApplication.getInstance().getCurrentRole().equals(Constants.ROLE_SGDZ)){
            // 施工队长
            switch (v.getId()){

                case R.id.btn_submit:

                    break;
                case R.id.btn_no_contact:
                    ActivityUtils.startActivity(OrderDetailActivity.this,ShuiGCannotInstallActivity.class);
                    break;
                case R.id.btn_sure_make_order:
                    ActivityUtils.startActivity(OrderDetailActivity.this,ShuiGPaiGongActivity.class);
                    break;


            }

        }



    }


    public void showBoHuiDialog() {

        final EditDialog dialog = new EditDialog(OrderDetailActivity.this);
        dialog.setCanceledOnTouchOutside(false);
        dialog.content("请输入驳回原因")
                .style(NormalDialog.STYLE_TWO)
                .title("驳回原因")
                .titleTextColor(Color.parseColor("#444444"))
                .titleTextSize(16)
                .contentTextSize(14)
                .contentTextColor(Color.parseColor("#444444"))
                .contentGravity(Gravity.CENTER)
                .showAnim(new ZoomInEnter())
                .dismissAnim(new ZoomOutExit())
                .cornerRadius(8)
                .show();

        dialog.setOnBtnClickL(
                new OnBtnClickL() {
                    @Override
                    public void onBtnClick() {

                        dialog.dismiss();
                    }
                },
                new OnBtnClickL() {
                    @Override
                    public void onBtnClick() {

                        // 驳回
                        RequestManager.getInstance().call(new OrderHandleApi(new OrderHandleApi.OrderHandleParams("","","",""), respOrderBoHuiListener, errorListener));

                        dialog.dismiss();

                    }
                });

    }


    public void showPaiDanDialog() {
        final NormalDialog dialog = new NormalDialog(OrderDetailActivity.this);
        dialog.setCanceledOnTouchOutside(false);
        dialog.content("确定审核通过此订单并派单吗?")
                .style(NormalDialog.STYLE_TWO)
                .title("")
                .titleTextSize(0)
                .contentTextSize(14)
                .contentTextColor(Color.parseColor("#444444"))
                .contentGravity(Gravity.CENTER)
                .showAnim(new ZoomInEnter())
                .dismissAnim(new ZoomOutExit())
                .cornerRadius(8)
                .show();

        dialog.setOnBtnClickL(
                new OnBtnClickL() {
                    @Override
                    public void onBtnClick() {


                        dialog.dismiss();
                    }
                },
                new OnBtnClickL() {
                    @Override
                    public void onBtnClick() {

                        ActivityUtils.startActivity(getApplicationContext(),ShuiGPaiDanActivity.class);
                        dialog.dismiss();

                    }
                });

    }


    Response.Listener<OrderHandleResult> respOrderBoHuiListener = new Response.Listener<OrderHandleResult>() {

        @Override
        public void onResponse(OrderHandleResult response) {

            if (HandleCode.requestSuccess()) {


                Log.i("juner", "juner respListener response : ");
            } else {



            }
        }
    };


    Response.ErrorListener errorListener = new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {

            Log.i("juner", "juner  error.getMessage(): " + error.getMessage());

        }
    };


    @Override
    public void initView() {

        if (UniApplication.getInstance().getCurrentRole().equals(Constants.ROLE_GRKH)){
            // 用户


        } else if (UniApplication.getInstance().getCurrentRole().equals(Constants.ROLE_SGGR)){
            // 施工工人
            btnSubmit.setVisibility(View.VISIBLE);
            bottomSgdz.setVisibility(View.GONE);
            btnSubmit.setText("安装完成");

        }else if (UniApplication.getInstance().getCurrentRole().equals(Constants.ROLE_JCY)){
            // 监察员
            btnSubmit.setVisibility(View.VISIBLE);
            bottomSgdz.setVisibility(View.GONE);
            btnSubmit.setText("监理抽查");

        }else if (UniApplication.getInstance().getCurrentRole().equals(Constants.ROLE_NQ)){
            // 内勤
            btnSubmit.setVisibility(View.GONE);
            bottomSgdz.setVisibility(View.VISIBLE);
            btnNoContact.setText("驳回");
            btnMakeOrder.setText("通过并派单");


        }else if (UniApplication.getInstance().getCurrentRole().equals(Constants.ROLE_SGDZ)){
            // 施工队长
            btnSubmit.setVisibility(View.GONE);
            bottomSgdz.setVisibility(View.VISIBLE);
        }

        if (!UniApplication.getInstance().getCurrentRole().equals(Constants.ROLE_SGGR)){
            // 非施工工人
            titleBar.addAction(new TitleBar.ImageAction(R.mipmap.ic_more) {
                @Override
                public void performAction(View view) {


                    if (UniApplication.getInstance().getCurrentRole().equals(Constants.ROLE_GRKH)){
                        // 用户
                        showGRKHSelectSheet();
                    }else if (UniApplication.getInstance().getCurrentRole().equals(Constants.ROLE_JCY)){
                        // 监察员
                        showSelectSheet();
                    }else if (UniApplication.getInstance().getCurrentRole().equals(Constants.ROLE_NQ)){
                        // 内勤
                        showGRKHSelectSheet();

                    }else if (UniApplication.getInstance().getCurrentRole().equals(Constants.ROLE_SGDZ)){
                        // 施工队长
                        showSelectSheet();
                    }

                }
            });
        }


    }

    private void showSelectSheet() {

        final String[] stringItems = {"查看抽查", "查看回访", "查看评论", "查看订单图片"};
        final ActionSheetDialog dialog = new ActionSheetDialog(OrderDetailActivity.this, stringItems, null);
        dialog.isTitleShow(false).show();

        dialog.setOnOperItemClickL(new OnOperItemClickL() {
            @Override
            public void onOperItemClick(AdapterView<?> parent, View view, int position, long id) {
                ActivityUtils.toast(stringItems[position]);
                dialog.dismiss();
                if (position == 0) {


                } else if (position == 1){


                } else if (position == 2){


                } else if (position == 3){

                    ActivityUtils.startActivity(getApplicationContext(),ShowOrderImgAllActivity.class);

                }


            }
        });
    }


    private void showGRKHSelectSheet() {

        final String[] stringItems = {"查看评论", "查看订单图片"};
        final ActionSheetDialog dialog = new ActionSheetDialog(OrderDetailActivity.this, stringItems, null);
        dialog.isTitleShow(false).show();

        dialog.setOnOperItemClickL(new OnOperItemClickL() {
            @Override
            public void onOperItemClick(AdapterView<?> parent, View view, int position, long id) {
                ActivityUtils.toast(stringItems[position]);
                dialog.dismiss();
                if (position == 0) {
                    Bundle bundle = new Bundle();
                    bundle.putString("order_id",getIntent().getStringExtra("order_id"));
                    LogUtils.i("order_id: " + getIntent().getStringExtra("order_id"));
                    ActivityUtils.startActivity(getApplicationContext(),ShuiGCommentActivity.class,bundle);
                } else if (position == 1){

                    ActivityUtils.startActivity(getApplicationContext(),ShowOrderImgAllActivity.class);
                }


            }
        });
    }


    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

        titleBar.setTitle("订单详情");
        LogUtils.i("order_id: " + getIntent().getStringExtra("order_id"));
        RequestManager.getInstance().call(new OrderDetailApi(new OrderDetailApi.OrderDetailParams(getIntent().getStringExtra("order_id")),
                respOrderDetailListener, errorListener));

    }

    Response.Listener<OrderDetailResult> respOrderDetailListener = new Response.Listener<OrderDetailResult>() {

        @Override
        public void onResponse(OrderDetailResult response) {

            if (HandleCode.requestSuccess()) {





                Log.i("juner", "juner OrderDetailResult response : " + GsonHelper.writeValue(response));
            } else {



            }
        }
    };


    @Override
    public boolean hasTitleBar() {
        return true;
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_order_detail;
    }
}
